package io.characterStream.fileRorW.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

/*
图片文件加密解密
 */
public class test3 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("E:\\1.jpg");
        //创建集合（数组咱不知道长度），存储文件字节
        ArrayList<Integer> list = new ArrayList<>();
        int i;
        while((i=fis.read())!=-1){
            list.add(i);
        }
        fis.close();
        FileOutputStream fos = new FileOutputStream("E:\\1.jpg");
        for (Integer myByte : list) {
            //加密，字节异或2，解密再运行一次就行
            fos.write(myByte^2);
        }
        fos.close();
    }
}
